package com.wicket.okrframework.biz.service.nb;

import cn.hutool.core.bean.BeanUtil;
import com.wicket.okrcomponent.common.annotations.BanAuto;
import com.wicket.okrframework.biz.service.dto.common.MergeInductionRecordDto;
import com.wicket.okrframework.biz.service.dto.req.*;
import com.wicket.okrframework.biz.service.dto.res.*;
import com.wicket.okrframework.common.baseinfo.BaseInfoDO;
import com.wicket.okrframework.common.baseinfo.BaseInfoHolder;
import com.wicket.okrframework.common.exception.BizException;
import com.wicket.okrframework.common.util.CommonFunctionHelper;
import com.wicket.okrframework.common.util.RedisUtil;
import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * @author ： 手工接入方法
 * @since 2022/5/28 15:32
 *
 *
 * @version 1.0
 */
@Service
public class NbBatch {
    /**
     * code:mergeChangeColumnList
     * name:M合并就职记录变更字段列表
     * desc:undefined
     **/

    @Resource
    private RedisUtil redisClient;



    @BanAuto
    @Trace(operationName = "M合并就职记录变更字段列表")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public MergeChangeColumnIrListRespDto mergeChangeColumnIrList(MergeChangeColumnIrListReqDto reqDto) {
        MergeChangeColumnIrListRespDto retData = new MergeChangeColumnIrListRespDto();
        for (OrgInductionRecordDto manInc : reqDto.getOrgInductionRecordList()) {
            OrgInductionRecordDto retElm = new OrgInductionRecordDto();
            BeanUtil.copyProperties(manInc, retElm);
            for (MergeInductionRecordDto mergeInc : reqDto.getMergeInductionRecordList()) {
                if (manInc.getInductionRecordId().equals(mergeInc.getInductionRecordId())) {
                    retElm.setDirectorInductionRecordId(mergeInc.getDirectorInductionRecordId());
                }
            }
            retData.getOrgInductionRecordList().add(retElm);
        }
        return retData;
    }

    /**
     * code:batchClearUserInfoFromRedis
     * name:Redis批量清空用户信息
     * desc:undefined
     **/
    @BanAuto
    @Trace(operationName = "Redis批量清空用户信息")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public BatchClearUserInfoFromRedisRespDto batchClearUserInfoFromRedis(BatchClearUserInfoFromRedisReqDto reqDto) {
        BatchClearUserInfoFromRedisRespDto retData = new BatchClearUserInfoFromRedisRespDto();
        if (reqDto.getBeginMemberList() == null || reqDto.getBeginMemberList().isEmpty()) {
            return retData;
        }
        for (String member : reqDto.getBeginMemberList()) {
            redisClient.delete("userbase-" + member);
            redisClient.delete("inductionInfo-" + member);
        }
        return retData;
    }

    /**
     * code:getDataCount
     * name:M计算新增数值（特殊方法）
     * desc:undefined
     **/
    @BanAuto
    @Trace(operationName = "M计算新增数值（特殊方法）")
    @Tags({@Tag(key = "参数", value = "arg[0]"),
            @Tag(key = "返回值", value = "returnedObj")})
    public AddCalculationAddAndSubRespDto addCalculationAddAndSub(AddCalculationAddAndSubReqDto reqDto) {
        AddCalculationAddAndSubRespDto retData = new AddCalculationAddAndSubRespDto();
        if (reqDto == null || reqDto.getStaffingId() == null) {
            retData.setStaffingNum(0L);
            return retData;
        }
        retData.setStaffingNum(1L);
        return retData;
    }
/**
      * code:receptionService
      * name:M1-获取接收字段（特殊方法）
      * desc:undefined
      * gen by moon at 8/10/2022, 3:13:41 AM
      * 
      **/
     @Trace(operationName = "M1-获取接收字段（特殊方法）")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public QueryReceiveFieldDetailRespDto queryReceiveFieldDetail(QueryReceiveFieldDetailReqDto reqDto) {

        return BeanUtil.toBean(reqDto,QueryReceiveFieldDetailRespDto.class);
      }
/**
      * code:publicFieldCache
      * name:M1执行底层框架公共字段推送内存（特殊方法）
      * desc:undefined
      * gen by moon at 9/10/2022, 5:04:44 PM
      * 
      **/
     @Trace(operationName = "M1执行底层框架公共字段推送内存（特殊方法）")
     @Tags({@Tag(key = "参数",value = "arg[0]"),
     @Tag(key = "返回值",value = "returnedObj")})
      public ImplementBottomPublicFieldPushMemoryRespDto implementBottomPublicFieldPushMemory(ImplementBottomPublicFieldPushMemoryReqDto reqDto) {
         if(BaseInfoHolder.contextHolder.get()==null){
             BaseInfoDO domain = new BaseInfoDO();
             domain.setSpecSpaceId(reqDto.getSpaceId());
             domain.setSpecInductionRecordId(reqDto.getCreateInductionId());
             domain.setSpecAppId(reqDto.getAppId());
             CommonFunctionHelper.setBaseInfoToLocal(domain);
         }
        return new ImplementBottomPublicFieldPushMemoryRespDto();
      }


    //手工接入方法
}
